<template>
	<view class="load" v-if="!load">
		<u-loading-icon mode="circle" inactive-color="#fff" text="正在加载..." vertical></u-loading-icon>
	</view>
	<view v-else>
		<u-search inputAlign="center" placeholder="搜索会员昵称/ID号" @search="search()"  v-model="searchValue" height="30"
			actionText="取消" :actionStyle="{color:'#fff'}" @custom="celSearch"></u-search>
		<x-scroll :fixed="true" @onRefresh="onRefresh" @scrolltolower="scrolltolower" :refresh="_freshing">
			<view class="list ">

				<view class="item wap" v-if="Array.isArray(list) && list.length > 0" v-for="item in list"
					:key="item.ID">
					<view class="cover" @click="nav_to(`/pages/user/user_visitor?id=${item.UserID}`)">
						<image :src="item.HeadImgUrl" mode="aspectFill" />
					</view>
					<view class="con" @click="nav_to(`/pages/user/user_visitor?id=${item.UserID}`)">
						<view class="name f1 c1">
							{{item.Name || "匿名"}}
							<view class="member member_hei" v-if="getUserType(item.UserType) == 1 ">黑金卡</view>
							<view class="member number_huan" v-if="getUserType(item.UserType) == 2">金卡</view>
							<view class="member" v-if="getUserType(item.UserType) == 0">普通用户</view>
						</view>
						<view class="time f2 c3">{{item.CreateTime}}</view>
					</view>
					<view class="name_fx" @click="nav_to(`/pages/user/user_visitor?id=${item.To_UserID}`)">{{item.To_Name}}
					</view>

				</view>
				<block v-else>
					<u-empty mode="list" width="64" height="64"
						icon="https://golfdate.oss-cn-shenzhen.aliyuncs.com/community/20230510114106.png" :show="true"
						iconSize="32" text="暂无数据"></u-empty>
				</block>
			</view>

		</x-scroll>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				load: false,
				_freshing: true,
				list: [],
				searchValue: '',
				PageIndex: 1, //页码
				PageSize: 10, //请求条数
				isMore:true,
				
				_Bhtype:'',
				_CDate:''
			}
		},
		onLoad(e) {
			
			this._CDate=e.d;
			this._Bhtype=e.t;
			
			if(this._Bhtype=='wx'){
				uni.setNavigationBarTitle({
					title: '加微信明细'
				});
			}else if(this._Bhtype=='friends'){
				uni.setNavigationBarTitle({
					title: '加好友明细'
				});
			}
			
			this.init();
		},
		onShow() {

		},
		methods: {
			clearRepetition(arr, key = "id") {
				let newArr = [];
				arr.forEach(item => {
					let index;
					let check = newArr.every((newItem, i) => {
						if (item[key] !== newItem[key]) {
							index = -1;
							return true;
						} else {
							index = i;
			
							return false;
						}
					})
					if (check) {
						newArr.push(item);
					} else {
						newArr.splice(index, 1, item);
					}
			
				})
				
				return newArr;
			},
			onRefresh() {
				this.PageIndex = 1;
				this.init();
			},
			//滚动到底部触发
			async scrolltolower() {
			  if (this.isMore) {
			    this.PageIndex++;
			    this.init();
			  }
			},
			prevAvatar(url) {
				uni.previewImage({
					current: 0,
					urls: [url]
				});
			},
			async init() {
				let res = await this.$api.post('/Manage/UserBehaviorItem', {
					BehaviorType: this._Bhtype,
					CreateTime: this._CDate
				});
				
				
				 this.list = res.data;
								 
				this.load = true;
			},
			async search() {
				
				this.list=[];
				
				let res = await this.$api.post('/Manage/UserBehaviorItem', {
					BehaviorType: this._Bhtype,
					CreateTime: this._CDate,
					Keywords:this.searchValue
				});
				this.list = res.data;
				
				this.load = true;
			},
			async celSearch() {
				this.searchValue = "";
				this.search();
			}
			
		},
		computed: {

			getUserType(l) {
				return l => {
					if (l.indexOf('黑金') != -1) {
						return 1
					} else if (l.indexOf('金') != -1) {
						return 2
					} else if (l.indexOf('银') != -1) {
						return 3
					} else {
						return 0
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.list {
		.item {
			display: flex;
			height: 180rpx;
			align-items: center;

			.cover {
				height: 100rpx;
				width: 100rpx;
				border-radius: 50%;
				overflow: hidden;
				border: 1px solid #333;

				image {

					height: 100%;
					width: 100%;
				}
			}

			.con {
				padding-left: 20rpx;
				flex: 1;

				.time {
					margin-top: 10rpx;
				}
			}

			.name_fx {
				height: 48rpx;
				line-height: 48rpx;
				text-align: center;
				color: #fff;
				text-decoration: underline;
			}

			.member {
				display: inline-block;
				vertical-align: middle;
				width: 68rpx;
				height: 32rpx;
				text-align: center;
				color: #fff;
				font-size: 16rpx;
				line-height: 32rpx;
				margin-left: 20rpx;
			}

			.number_huan {
				color: #4C310C;
				background: linear-gradient(180deg, #FDF9F6 0%, #E1C4A6 100%);
				border: 2rpx solid #E6CEB5;
			}

			.number_hei {
				color: #ffffff;
				background: linear-gradient(135deg, #7E7E7E 0%, #292929 100%);
				border: 2rpx solid #E6CEB5;
			}


		}

		
	}
</style>